﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace MvcApplication1.Models
{
    public partial class Jugadore
    {
        public bool EsValido
        {
            get { return (GetViolacionesDeReglas().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetViolacionesDeReglas()
        {
            if(string.IsNullOrWhiteSpace(this._Apellido))
                yield return new RuleViolation("Apellido Requerido","_Apellido");
            if(string.IsNullOrWhiteSpace(this._Nombre))
                yield return new RuleViolation("Nombre Requerido","_Nombre");
        }
        

        partial void OnValidate(ChangeAction action)
        {
            if (!EsValido)
                throw new ApplicationException("Rule violations prevent saving");
        }

        public override string ToString()
        {
            return this._Nombre + " " + this._Apellido;
        }
    }
}